<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="定义：1-初始化；2-登录中；3-执行中；4-执行成功；5-执行失败；6-执行异常；" prop="code">
      <el-input v-model="dataForm.code" placeholder="定义：1-初始化；2-登录中；3-执行中；4-执行成功；5-执行失败；6-执行异常；"></el-input>
    </el-form-item>
    <el-form-item label="微信登录二维码" prop="wxqrcode">
      <el-input v-model="dataForm.wxqrcode" placeholder="微信登录二维码"></el-input>
    </el-form-item>
    <el-form-item label="进度" prop="schedule">
      <el-input v-model="dataForm.schedule" placeholder="进度"></el-input>
    </el-form-item>
    <el-form-item label="错误日志" prop="description">
      <el-input v-model="dataForm.description" placeholder="错误日志"></el-input>
    </el-form-item>
    <el-form-item label="CDKEY" prop="cdkey">
      <el-input v-model="dataForm.cdkey" placeholder="CDKEY"></el-input>
    </el-form-item>
    <el-form-item label="1.只检测2清理并检测3强制重启" prop="cleantype">
      <el-input v-model="dataForm.cleantype" placeholder="1.只检测2清理并检测3强制重启"></el-input>
    </el-form-item>
    <el-form-item label="激活码类型 0小时卡1天卡2周卡3月卡4年卡" prop="datetype">
      <el-input v-model="dataForm.datetype" placeholder="激活码类型 0小时卡1天卡2周卡3月卡4年卡"></el-input>
    </el-form-item>
    <el-form-item label="" prop="sn">
      <el-input v-model="dataForm.sn" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="0未处理 1已处理" prop="status">
      <el-input v-model="dataForm.status" placeholder="0未处理 1已处理"></el-input>
    </el-form-item>
    <el-form-item label="" prop="cdktype">
      <el-input v-model="dataForm.cdktype" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="wxid">
      <el-input v-model="dataForm.wxid" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="remark">
      <el-input v-model="dataForm.remark" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createdDate">
      <el-input v-model="dataForm.createdDate" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="最后更新时间" prop="lastUpdatedDate">
      <el-input v-model="dataForm.lastUpdatedDate" placeholder="最后更新时间"></el-input>
    </el-form-item>
    <el-form-item label="0" prop="version">
      <el-input v-model="dataForm.version" placeholder="0"></el-input>
    </el-form-item>
    <el-form-item label="添加的微信好友" prop="addWxid">
      <el-input v-model="dataForm.addWxid" placeholder="添加的微信好友"></el-input>
    </el-form-item>
    <el-form-item label="添加的微信提示语" prop="addText">
      <el-input v-model="dataForm.addText" placeholder="添加的微信提示语"></el-input>
    </el-form-item>
    <el-form-item label="添加的微信公众号好友" prop="addGhid">
      <el-input v-model="dataForm.addGhid" placeholder="添加的微信公众号好友"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          code: '',
          wxqrcode: '',
          schedule: '',
          description: '',
          cdkey: '',
          cleantype: '',
          datetype: '',
          sn: '',
          status: '',
          cdktype: '',
          wxid: '',
          remark: '',
          createdDate: '',
          lastUpdatedDate: '',
          version: '',
          addWxid: '',
          addText: '',
          addGhid: ''
        },
        dataRule: {
          code: [
            { required: true, message: '定义：1-初始化；2-登录中；3-执行中；4-执行成功；5-执行失败；6-执行异常；不能为空', trigger: 'blur' }
          ],
          wxqrcode: [
            { required: true, message: '微信登录二维码不能为空', trigger: 'blur' }
          ],
          schedule: [
            { required: true, message: '进度不能为空', trigger: 'blur' }
          ],
          description: [
            { required: true, message: '错误日志不能为空', trigger: 'blur' }
          ],
          cdkey: [
            { required: true, message: 'CDKEY不能为空', trigger: 'blur' }
          ],
          cleantype: [
            { required: true, message: '1.只检测2清理并检测3强制重启不能为空', trigger: 'blur' }
          ],
          datetype: [
            { required: true, message: '激活码类型 0小时卡1天卡2周卡3月卡4年卡不能为空', trigger: 'blur' }
          ],
          sn: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '0未处理 1已处理不能为空', trigger: 'blur' }
          ],
          cdktype: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          wxid: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          createdDate: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          lastUpdatedDate: [
            { required: true, message: '最后更新时间不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '0不能为空', trigger: 'blur' }
          ],
          addWxid: [
            { required: true, message: '添加的微信好友不能为空', trigger: 'blur' }
          ],
          addText: [
            { required: true, message: '添加的微信提示语不能为空', trigger: 'blur' }
          ],
          addGhid: [
            { required: true, message: '添加的微信公众号好友不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/cards/amgcdktasks/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.code = data.amgcdktasks.code
                this.dataForm.wxqrcode = data.amgcdktasks.wxqrcode
                this.dataForm.schedule = data.amgcdktasks.schedule
                this.dataForm.description = data.amgcdktasks.description
                this.dataForm.cdkey = data.amgcdktasks.cdkey
                this.dataForm.cleantype = data.amgcdktasks.cleantype
                this.dataForm.datetype = data.amgcdktasks.datetype
                this.dataForm.sn = data.amgcdktasks.sn
                this.dataForm.status = data.amgcdktasks.status
                this.dataForm.cdktype = data.amgcdktasks.cdktype
                this.dataForm.wxid = data.amgcdktasks.wxid
                this.dataForm.remark = data.amgcdktasks.remark
                this.dataForm.createdDate = data.amgcdktasks.createdDate
                this.dataForm.lastUpdatedDate = data.amgcdktasks.lastUpdatedDate
                this.dataForm.version = data.amgcdktasks.version
                this.dataForm.addWxid = data.amgcdktasks.addWxid
                this.dataForm.addText = data.amgcdktasks.addText
                this.dataForm.addGhid = data.amgcdktasks.addGhid
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/cards/amgcdktasks/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'code': this.dataForm.code,
                'wxqrcode': this.dataForm.wxqrcode,
                'schedule': this.dataForm.schedule,
                'description': this.dataForm.description,
                'cdkey': this.dataForm.cdkey,
                'cleantype': this.dataForm.cleantype,
                'datetype': this.dataForm.datetype,
                'sn': this.dataForm.sn,
                'status': this.dataForm.status,
                'cdktype': this.dataForm.cdktype,
                'wxid': this.dataForm.wxid,
                'remark': this.dataForm.remark,
                'createdDate': this.dataForm.createdDate,
                'lastUpdatedDate': this.dataForm.lastUpdatedDate,
                'version': this.dataForm.version,
                'addWxid': this.dataForm.addWxid,
                'addText': this.dataForm.addText,
                'addGhid': this.dataForm.addGhid
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
